from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer

from .models.User import User

# Create your views here.
class HelloWorld(APIView):
  def get(self, request):
    return Response({"message": "Hello, World!"})

class UserInfo(APIView):
  renderer_classes = [JSONRenderer]

  def get(self, request):
    # 查询 User 模型中的数据
    users = User.objects.all()
    print('users:', users)

    # 将 users 转换为 JSON 格式, 并返回数据
    return Response(users.values(), content_type="application/json")

    # user_info = {
    #   "username": "John Doe",
    # }

    # return Response(user_info, content_type="application/json")